package com.spring.zy.controller;

import com.spring.zy.model.Animal;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/fc")
public class FirstController {

    @RequestMapping("/index")
    public String index(){
        /*jsp页面*/
        return "view";
    }
    /*对象接收*/
    @RequestMapping("/madeth1")
    public String madeth1(Animal animal){
        System.out.println("name:"+animal.getName());
        System.out.println("age:"+animal.getAge());
        return "Success";
    }
    /*参数接收*/
    @RequestMapping("/madeth2")
    public String madeth2(String name,Integer age ){
        System.out.println("name:"+name);
        System.out.println("age:"+age);
        return "Success";
    }
    /*@RequestParam 注解接收*/
    @RequestMapping("/madeth3")
    public String madeth3(@RequestParam("name") String name,
                          @RequestParam("age") Integer age){
        System.out.println("name:"+name);
        System.out.println("age:"+age);
        return "Success";
    }
    /*URL路径接收*/
    @RequestMapping("/url/{name},{age}")
    public String madeth4(@PathVariable("name") String name,@PathVariable("age") Integer age){
        System.out.println("name:"+name);
        System.out.println("age:"+age);
        return "Success";
    }
    /*ModelAttribute注解接收*/
    @RequestMapping("/madeth5")
    public String madeth(@ModelAttribute("name") String name,
                         @ModelAttribute("age") Integer age){
        System.out.println("name:"+name);
        System.out.println("age:"+age);
        return "Success";
    }



//    /*转发*/
//    @RequestMapping("/forward1")
//    public String forward1(){
//        return "forward:/demo/forward";
//    }
//    @RequestMapping( "/forward2")
//    public String forward2(){
//        return "forward";
//    }
//    /*重定向*/
//    @RequestMapping("/redirect1")
//    public String redirect1(){
//        return "redirect:/demo/forward2";
//    }
//    @RequestMapping("/redirect2")
//    public String redirect2(){
//        return "redirect";
//    }
//    /*重定向  其他类中*/
//    @RequestMapping("/redirectTest")
//    public String redirect3(){
//        return "redirect:/test/index";
//    }
}
